<template>
  <div class="app-container">
    <el-drawer
      :title="title"
      :visible.sync="openDetail"
      size="80%"
      @close="cancel"
      :append-to-body="true"
    >
      <template v-slot:title>
        <span class="titleDiv">{{ title }}</span>
      </template>
      <div style="padding: 0 20px; height: calc(100% - 100px)">
        <el-table
          v-loading="loading"
          :data="itemrecptlineList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column
            label="序号"
            align="center"
            width="50px"
            prop="issueCode"
          >
            <template slot-scope="scope">
              <span>{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="产品物料编码"
            align="center"
            width="120px"
            prop="itemCode"
          />
          <el-table-column
            label="产品物料名称"
            align="center"
            prop="itemName"
          />
          <el-table-column
            label="规格型号"
            align="center"
            prop="specification"
          />
          <el-table-column
            label="SN码（序列号）"
            align="center"
            prop="snCode"
          />
          <el-table-column label="批次号" align="center" prop="batchCode" />
        </el-table>
      </div>
      <div style="text-align: right; margin-top: 14px; margin-right: 20px">
        <el-button type="primary" @click="handlePrint">打印</el-button>
      </div>
    </el-drawer>
  </div>
</template>
    
<script>
import { getSnCode } from "@/api/mes/qc/iqc";
import { printItem } from "@/api/mes/wm/itemrecpt";
export default {
  data() {
    return {
      ids:[],
      rowData: {},
      openDetail: false,
      title: "查看批次号详情",
      warehouseInfo: [],
      loading: false,
      itemrecptlineList: [],
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        recptLineId: null,
      },
      wmItemRecptItemList:[],
    };
  },
  components: {},
  dicts: ["mes_order_status"],
  methods: {
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.iqcId);
    },
    handlePrint(){
      if (this.ids && this.ids.length) {
        getSnCode(this.ids).then((res) => {
          console.log(res, "打印前需要调的接口res");
          if (res.code === 200) {
            this.wmItemRecptItemList = res.data ? res.data : [];
            if (this.wmItemRecptItemList.length) {
              this.$modal
                .confirm('是否确认打印物料编号为"' + this.ids + '"的数据项？')
                .then(() => {
                  return printItem(this.wmItemRecptItemList);
                })
                .then(() => {
                  this.$modal.msgSuccess("打印成功");
                })
                .catch(() => {
                  // 处理异常情况
                  console.error("打印出错");
                });
            } else {
              this.$message.warning("请先选择需要打印的数据！");
            }
          } else {
            // 处理接口返回的错误信息
            console.error("接口调用失败:", response.message);
          }
        });
      } else {
        this.$message.warning("请先选择需要打印的数据！");
      }
    },
    //初始化函数
    init(row) {
      this.rowData = row;
      console.log(row, "子组件的row");
      this.openDetail = true;
      this.queryParams.recptLineId = row.lineId;
      this.getList();
    },
    getList() {
      this.loading = true;
      getSnCode([this.rowData.iqcId]).then((response) => {
        this.itemrecptlineList = response.data || [];
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.openDetail = false;
    },
  },
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.app-container ::v-deep .el-drawer__header {
  padding-top: 10px !important;
  padding-bottom: 5px !important;
  margin-bottom: 10px !important;
}

.bg-purple {
  display: flex;
  align-items: center;
  span:nth-child(1) {
    display: inline-block;
    // width: 100px;
    margin-right: 10px;
    white-space: nowrap;
    line-height: 30px;
  }
}
.titleDiv {
  font-weight: 700 !important;
  font-size: 20px;
}
</style>
    